package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.CmsSubject;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.CmsSubjectDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface CmsSubjectMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, categoryId, title, pic, productCount, recommendStatus, createTime, collectCount, readCount, commentCount, albumPics, description, showStatus, forwardCount, categoryName, content);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(CmsSubject record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(categoryId).equalTo(record::getCategoryId)
                  .set(title).equalTo(record::getTitle)
                  .set(pic).equalTo(record::getPic)
                  .set(productCount).equalTo(record::getProductCount)
                  .set(recommendStatus).equalTo(record::getRecommendStatus)
                  .set(createTime).equalTo(record::getCreateTime)
                  .set(collectCount).equalTo(record::getCollectCount)
                  .set(readCount).equalTo(record::getReadCount)
                  .set(commentCount).equalTo(record::getCommentCount)
                  .set(albumPics).equalTo(record::getAlbumPics)
                  .set(description).equalTo(record::getDescription)
                  .set(showStatus).equalTo(record::getShowStatus)
                  .set(forwardCount).equalTo(record::getForwardCount)
                  .set(categoryName).equalTo(record::getCategoryName)
                  .set(content).equalTo(record::getContent);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(CmsSubject record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(categoryId).equalToWhenPresent(record::getCategoryId)
                  .set(title).equalToWhenPresent(record::getTitle)
                  .set(pic).equalToWhenPresent(record::getPic)
                  .set(productCount).equalToWhenPresent(record::getProductCount)
                  .set(recommendStatus).equalToWhenPresent(record::getRecommendStatus)
                  .set(createTime).equalToWhenPresent(record::getCreateTime)
                  .set(collectCount).equalToWhenPresent(record::getCollectCount)
                  .set(readCount).equalToWhenPresent(record::getReadCount)
                  .set(commentCount).equalToWhenPresent(record::getCommentCount)
                  .set(albumPics).equalToWhenPresent(record::getAlbumPics)
                  .set(description).equalToWhenPresent(record::getDescription)
                  .set(showStatus).equalToWhenPresent(record::getShowStatus)
                  .set(forwardCount).equalToWhenPresent(record::getForwardCount)
                  .set(categoryName).equalToWhenPresent(record::getCategoryName)
                  .set(content).equalToWhenPresent(record::getContent);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<CmsSubject> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("CmsSubjectResult")
    Optional<CmsSubject> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "CmsSubjectResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "category_id", property = "categoryId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pic", property = "pic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_count", property = "productCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "recommend_status", property = "recommendStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "collect_count", property = "collectCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "read_count", property = "readCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "comment_count", property = "commentCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "album_pics", property = "albumPics", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "show_status", property = "showStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "forward_count", property = "forwardCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "category_name", property = "categoryName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<CmsSubject> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, cmsSubject, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, cmsSubject, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(CmsSubject record) {
        return MyBatis3Utils.insert(this::insert, record, cmsSubject, c ->
                c.map(categoryId).toProperty("categoryId")
                 .map(title).toProperty("title")
                 .map(pic).toProperty("pic")
                 .map(productCount).toProperty("productCount")
                 .map(recommendStatus).toProperty("recommendStatus")
                 .map(createTime).toProperty("createTime")
                 .map(collectCount).toProperty("collectCount")
                 .map(readCount).toProperty("readCount")
                 .map(commentCount).toProperty("commentCount")
                 .map(albumPics).toProperty("albumPics")
                 .map(description).toProperty("description")
                 .map(showStatus).toProperty("showStatus")
                 .map(forwardCount).toProperty("forwardCount")
                 .map(categoryName).toProperty("categoryName")
                 .map(content).toProperty("content")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(CmsSubject record) {
        return MyBatis3Utils.insert(this::insert, record, cmsSubject, c ->
                c.map(categoryId).toPropertyWhenPresent("categoryId", record::getCategoryId)
                 .map(title).toPropertyWhenPresent("title", record::getTitle)
                 .map(pic).toPropertyWhenPresent("pic", record::getPic)
                 .map(productCount).toPropertyWhenPresent("productCount", record::getProductCount)
                 .map(recommendStatus).toPropertyWhenPresent("recommendStatus", record::getRecommendStatus)
                 .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
                 .map(collectCount).toPropertyWhenPresent("collectCount", record::getCollectCount)
                 .map(readCount).toPropertyWhenPresent("readCount", record::getReadCount)
                 .map(commentCount).toPropertyWhenPresent("commentCount", record::getCommentCount)
                 .map(albumPics).toPropertyWhenPresent("albumPics", record::getAlbumPics)
                 .map(description).toPropertyWhenPresent("description", record::getDescription)
                 .map(showStatus).toPropertyWhenPresent("showStatus", record::getShowStatus)
                 .map(forwardCount).toPropertyWhenPresent("forwardCount", record::getForwardCount)
                 .map(categoryName).toPropertyWhenPresent("categoryName", record::getCategoryName)
                 .map(content).toPropertyWhenPresent("content", record::getContent)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<CmsSubject> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, cmsSubject, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<CmsSubject> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, cmsSubject, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<CmsSubject> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, cmsSubject, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<CmsSubject> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, cmsSubject, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(CmsSubject record) {
        return update(c ->
                c.set(categoryId).equalTo(record::getCategoryId)
                 .set(title).equalTo(record::getTitle)
                 .set(pic).equalTo(record::getPic)
                 .set(productCount).equalTo(record::getProductCount)
                 .set(recommendStatus).equalTo(record::getRecommendStatus)
                 .set(createTime).equalTo(record::getCreateTime)
                 .set(collectCount).equalTo(record::getCollectCount)
                 .set(readCount).equalTo(record::getReadCount)
                 .set(commentCount).equalTo(record::getCommentCount)
                 .set(albumPics).equalTo(record::getAlbumPics)
                 .set(description).equalTo(record::getDescription)
                 .set(showStatus).equalTo(record::getShowStatus)
                 .set(forwardCount).equalTo(record::getForwardCount)
                 .set(categoryName).equalTo(record::getCategoryName)
                 .set(content).equalTo(record::getContent)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(CmsSubject record) {
        return update(c ->
                c.set(categoryId).equalToWhenPresent(record::getCategoryId)
                 .set(title).equalToWhenPresent(record::getTitle)
                 .set(pic).equalToWhenPresent(record::getPic)
                 .set(productCount).equalToWhenPresent(record::getProductCount)
                 .set(recommendStatus).equalToWhenPresent(record::getRecommendStatus)
                 .set(createTime).equalToWhenPresent(record::getCreateTime)
                 .set(collectCount).equalToWhenPresent(record::getCollectCount)
                 .set(readCount).equalToWhenPresent(record::getReadCount)
                 .set(commentCount).equalToWhenPresent(record::getCommentCount)
                 .set(albumPics).equalToWhenPresent(record::getAlbumPics)
                 .set(description).equalToWhenPresent(record::getDescription)
                 .set(showStatus).equalToWhenPresent(record::getShowStatus)
                 .set(forwardCount).equalToWhenPresent(record::getForwardCount)
                 .set(categoryName).equalToWhenPresent(record::getCategoryName)
                 .set(content).equalToWhenPresent(record::getContent)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
